cmake_minimum_required(VERSION 3.13)
project(wbcoro CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# options for building tests and examples
option(BUILD_TESTS "Build test cases, default is ON" ON)
option(BUILD_EXAMPLES "Build example codes, default is ON" ON)

message("${PROJECT_NAME} build tests: ${BUILD_TESTS}")
message("${PROJECT_NAME} build examples: ${BUILD_EXAMPLES}")

# examine gcc version
if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
    if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "11.1.0")
        message(FATAL_ERROR "GCC-${CMAKE_CXX_COMPILER_VERSION} not supported, use GCC-11.1.0 or above")
    else()
        message("Using GCC-${CMAKE_CXX_COMPILER_VERSION} to build")
    endif()
else()
    message(FATAL_ERROR "Supports only GCC compiler")
    return()
endif()

if(BUILD_TESTS)
    add_subdirectory(${PROJECT_SOURCE_DIR}/tests)
endif()

if(BUILD_EXAMPLES)
    add_subdirectory(${PROJECT_SOURCE_DIR}/examples)
endif()

add_library(${PROJECT_NAME} STATIC "")
add_subdirectory(src)
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20)
include(GNUInstallDirs)

set(build_include_dirs
    "${PROJECT_SOURCE_DIR}/wbcoro"
    "${PROJECT_SOURCE_DIR}/test"
    "${PROJECT_SOURCE_DIR}/examples")

include_directories(${build_include_dirs})
message("${build_include_dirs}")

# support to be a part of parent build
target_include_directories(${PROJECT_NAME} SYSTEM INTERFACE
    "$<BUILD_INTERFACE:${build_include_dirs}>"
    "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")

# installation configuration
set_target_properties(${PROJECT_NAME}
    PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
    LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
    ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")

install(DIRECTORY "${PROJECT_SOURCE_DIR}/${PROJECT_NAME}/include/"
    DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")

install(TARGETS ${PROJECT_NAME}
    RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
    ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
    LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
